/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package co.edu.univalle.persistencia;

import co.edu.univalle.modelo.Ciaenvios;
import co.edu.univalle.modelo.Clientes;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author valentina
 */
@Stateless
public class ClientesDAO implements IClientesDAO {

        
     @PersistenceContext
    private EntityManager entityManager;


    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")

    @Override
    public void registrar(Clientes cliente) {
         try{
         entityManager.persist(cliente);
     }
     catch (RuntimeException e){
     throw e;
    }
}
    
    

    @Override
    public void modificar(Clientes cliente) {
        
            try{
         entityManager.merge(cliente);
     }
     catch (RuntimeException e){
     throw e;
     }
 }

    
    @Override
    public void eliminar(Clientes cliente) {
       
            try{
         entityManager.remove(cliente);
     }
     catch (RuntimeException e){
     throw e;
    }
 }

    @Override
    public List<Clientes> consultar() {
        
             try{
                String jpql = "SELECT c FROM Clientes c";
                Query query = entityManager.createQuery(jpql);
                return query.getResultList();
         
     }
     catch (RuntimeException e){
     throw e;
}
    }

    @Override
    public Clientes consultarPorIdCliente(Integer idcliente) {
              try{
                    return entityManager.find(Clientes.class, idcliente);
     }
                
     catch (RuntimeException e){
     throw e;
       
        }
    }
}
